Page({

  /**
   * 页面的初始数据
   */
  data: {
    token: '',
    // 传递过来的参数
    index: '',
    // 修改摄像头信息请求参数
    id: '',
    deviceId: '',
    name: '',
    ip: '',
    account: '',
    password: '',
    port: '',
    type: '',
    functions: '',
    drawData: '',
    mobile: '',
    // 播放监控视频
    imgList: [],
  },
  jumpHome: function () {
    wx.redirectTo({
      url: '../home/home',
    })
  },
  jumpWarn: function () {
    wx.redirectTo({
      url: '../warn/warn',
    })
  },
  jumpCamera: function () {
    wx.redirectTo({
      url: 'camera',
    })
  },
  jumpServer: function () {
    wx.redirectTo({
      url: '../server/server',
    })
  },
  cameraSave() {
    let that = this;
    wx.getStorage({
      key: 'token',
      success: function (res) {
        that.setData({
          token: res.data
        })

        let header = {
          'context-type': 'application/json',
          'UserToken': that.data.token,
          'Cookie': wx.getStorageSync("sessionid")
        }
        wx.request({
          url: 'https://www.2edge.cn/rest/camera/update/f6822589647d41a49847ab8db4bd0c26/2f8a73e88c54447ea535929d0818bda6',
          method: 'post',
          header: header,
          data: {
            "id": that.data.id,
            "deviceId": that.data.deviceId,
            "name": that.data.name,
            "ip": that.data.ip,
            "account": that.data.account,
            "password": that.data.password,
            "port": that.data.port,
            "type": that.data.type,
            "functions": that.data.functions,
            "drawData": that.data.drawData,
            "mobile": that.data.mobile
          },
          success: function (res) {
            console.log(res);
            if (res.statusCode === 200 && res.data.status == 'true') {
              wx.showToast({
                title: '成功',
                icon: 'success',
                duration: 2000//持续的时间
              })
              wx.redirectTo({
                url: '../camera/camera',
              })
            }else {
              wx.showToast({
                title: '设备不在线',
                icon: 'loading',
                duration: 5000//持续的时间
              })
            }
          }
        })
      }
    })

  },
  operatrun() {
    wx.showToast({
      title: '正在运行'
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      index: options.index
    })
    // console.log(this.data.index);
    let that = this;
    wx.getStorage({
      key: 'token',
      success: function (res) {
        that.setData({
          token: res.data
        })

        let header = {
          'context-type': 'application/json',
          'UserToken': that.data.token,
          'Cookie': wx.getStorageSync("sessionid")
        }
        wx.request({
          url: 'https://www.2edge.cn/rest/camera/queryList',
          method: 'post',
          header: header,
          data: {
            "pageNum": '',
            "pageSise": '',
            "conditions": []
          },
          success: function (res) {
            let recordArr = res.data.data.records
            var index = that.data.index
            let imgList = []

            let id = [];
            let deviceId = [];
            let name = [];
            let ip = [];
            let account = [];
            let password = [];
            let port = [];
            let type = [];
            let functions = [];
            let mobile = []

            recordArr.forEach(function (item, index) {
              // console.log(item.id);
              id.push(item.id);
              deviceId.push(item.deviceId);
              name.push(item.locationName);
              ip.push(item.ip);
              account.push(item.account);
              password.push(item.password);
              port.push(item.port);
              type.push(item.type);
              functions.push(item.functions);
              mobile.push(item.mobile)

              imgList[index] = { "ws": false, "imageUrl": "https://www.2edge.cn/cameras/" + item.id + ".jpg" }
            });


            that.setData({
              id: id[index],
              deviceId: deviceId[index],
              name: name[index],
              ip: ip[index],
              account: account[index],
              password: password[index],
              port: port[index],
              type: type[index],
              functions: functions[index],
              mobile: mobile[index],

              imgList: imgList
            })
            // console.log(that.data.ip);
          }
        })
      }
    })
  },


})